﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Class_Entity;
using BussinessObject;
using System.Data;
using System.Data.SqlClient;


public partial class WebApplication_ADEditContactUs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadData();

        }
    }


    private void loadData()
    {
        int id = Convert.ToInt32(Session["ID"].ToString());

        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();

        cu.ID = id;

        DataTable dt = new DataTable();
        dt = bocu.Find_ContactUs(cu).Tables[0];
        txtName.Text = dt.Rows[0]["Name"].ToString();
        txtAddress.Text = dt.Rows[0]["Address"].ToString();
        txtPhone.Text = dt.Rows[0]["Phone"].ToString();
        txtFax.Text = dt.Rows[0]["Fax"].ToString();
      


    }

    protected void btSubmit_Click(object sender, EventArgs e)
    {
        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();
        int id = Convert.ToInt32(Session["ID"].ToString());
        cu.ID = id;

        DataTable dt = new DataTable();
        dt = bocu.Find_ContactUs(cu).Tables[0];

        cu.BranchName = txtName.Text.Trim();
        cu.Address = txtAddress.Text.Trim();
        cu.Phone = Convert.ToInt32(txtPhone.Text.Trim());
        cu.Fax = Convert.ToInt32(txtFax.Text.Trim());
        

        bocu.Edit_ContactUs(cu);


        Response.Write("<script>alert('Update success !')</script>");
        Response.Redirect("ADContactUs.aspx");
    }
    
}